local lunshi = fk.CreateSkill {
  name = "lunshi",
}

lunshi:addEffect("active", {
  anim_type = "control",
  card_num = 0,
  target_num = 1,
  prompt = "#lunshi",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter=function (self, player, to_select, selected, selected_cards, card, extra_data)
    return #selected == 0
  end,
  on_use = function(self, room, effect)
    local target = effect.tos[1]
    local n = #table.filter(room.alive_players, function(p) return target:inMyAttackRange(p) end)
    if n > 0 and target:getHandcardNum() < 5 then
      target:drawCards(math.min(n, 5 - target:getHandcardNum()), self.name)
    end
    if target.dead then return end
    n = #table.filter(room.alive_players, function(p) return p:inMyAttackRange(target) end)
    if n > 0 then
      room:askForDiscard(target, n, n, true, self.name, false)
    end
  end,
})

return lunshi